package part13;

/**
 * @author wcj
 * @Date 2021/5/24 16:28
 * @Version 1.0
 */
public class Part138 {

    /**
     * 将二进制文件转为16进制形式
     *
     * @param data
     * @return
     */
    public static String format(byte[] data) {
        StringBuilder res = new StringBuilder();
        int n = 0;
        for (byte b : data) {
            if (n % 16 == 0) {
                res.append(String.format("%05X:", n));
            }
            res.append(String.format("%02X ", b));
            n++;
            if (n % 16 == 0) {
                res.append("\n");
            }
        }
        res.append("\n");
        return res.toString();
    }

    public static void main(String[] args) {

    }
}
